<template>
  <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
    <a-form>
      <a-form-item
          label="参选企业"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
      >
        <a-input  :placeholder="(company.company_name)" :disabled="true"/>
      </a-form-item>
<!--      用户名-->
      <a-form-item
          :label="$t('title')"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
          :required="true"
      >
        <a-input :placeholder="$t('titleInput')" v-model="item.company_username">
          <a-icon slot="prefix" type="user" />
        </a-input>
      </a-form-item>
      <a-form-item
          label="密码"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
          :required="true"
      >
        <a-input-password  placeholder="密码不小于6位" v-model="item.company_userpass"/>
      </a-form-item>
      <a-form-item
          label="姓名"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
          :required="true"
      >
        <a-input placeholder="负责人姓名" v-model="item.company_userrealname"/>
      </a-form-item>
      <a-form-item
          :label="$t('customer')"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
          :required="true"
      >
        <a-input :placeholder="$t('customerInput')" v-model="item.company_userphone">
          <a-icon slot="prefix" type="phone" />
        </a-input>
      </a-form-item>


      <a-form-item style="margin-top: 24px" :wrapperCol="{span: 10, offset: 7}">
        <a-button type="primary" @click="submitChange">{{$t('submit')}}</a-button>
        <a-button style="margin-left: 8px"><a ref="#/list/add-enterprise">返回</a></a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
import Axios from 'axios'
export default {
  name: 'ModifyDeclarant',
  i18n: require('./i18n'),
  data () {
    return {
      url: this.$store.state.apiUrl + ':' + this.$store.state.apiPort,
      value: 1,
      // 申报人信息
      item: this.$route.params.item,
      company: {},
    }
  },
  computed: {
    desc() {
      return "修改参选企业的负责人信息。"
    },
  },
  mounted() {
    this.item = this.$route.params.item
    // 根据申报人id查询公司
    this.getCompanyByUser()
  },
  methods: {
    submitChange() {
      Axios.post(this.url + '/pxManagerSystem/updateCompanyUsersByCompanyUsersId', {
        company_user_id: this.item.company_user_id,
        company_username: this.item.company_username,
        company_userpass: this.item.company_userpass,
        company_userrealname: this.item.company_userrealname,
        company_userphone: this.item.company_userphone
      }).then(res => {
        this.$message.info(res.data.message);
      }).catch(err => {
        this.$message.error('修改失败，请查看与后端连接')
        console.log(err)
      })
    },
    getCompanyByUser() {
      // 获取关系表
      Axios.post(this.url + '/pxManagerSystem/getCompanyInfoByCompanyUserId', {
        company_user_id: this.item.company_user_id
      }).then(res => {
        if(res.data.state === 200) {
          this.company = res.data.data.companyInfoList[0]
        }else {
          console.log(res)
          this.$message.error('访问后端失败，请检查网络连接')
          this.$message.error(res.data.message)
        }
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>

</style>
